import request from "@/utils/request";
const BASE_URL = "/customers";

const CustomerAPI = {
  getList(queryParams: Query) {
    return request<any, PageResult<PageVO[]>>({
      url: `${BASE_URL}/list`,
      method: "get",
      params: queryParams,
    });
  },
  getExpiredList(queryParams: Query) {
    return request<any, PageResult<PageVO[]>>({
      url: `${BASE_URL}/expiredList`,
      method: "get",
      params: queryParams,
    });
  },
  getFormData(id: number) {
    return request<any, Form>({
      url: `${BASE_URL}/${id}`,
      method: "get",
    });
  },

  add(data: Form) {
    return request({
      url: `${BASE_URL}/create`,
      method: "post",
      data: data,
    });
  },

  update(data: Form) {
    return request({
      url: `${BASE_URL}/update`,
      method: "POST",
      data: data,
    });
  },

  deleteByIds(id: number) {
    return request({
      url: `${BASE_URL}/delete/${id}`,
      method: "get",
    });
  },

  /**
   * customer resgister
   * @param data
   * @returns
   */
  doRegister(data: Form) {
    return request<any, PageVO>({
      url: `${BASE_URL}/register`,
      method: "post",
      data: data,
    });
  },

  activeRegister(data: ActiveForm) {
    return request({
      url: `${BASE_URL}/active`,
      method: "post",
      data: data,
    });
  },

  getCurrentLogedUsersCustomer() {
    return request<any, Customer>({
      url: `${BASE_URL}/getCurrentCustomer`,
      method: "get",
    });
  },

  uploadLogo(data: Customer) {
    return request({
      url: `${BASE_URL}/uploadLogo`,
      method: "post",
      data: data,
    });
  },

  getLogo() {
    return request<any, Customer>({
      url: `${BASE_URL}/logo`,
      method: "get",
    });
  },
  getRegionName(id: number) {
    return request<any, PageVO>({
      url: `${BASE_URL}/getRegionName/${id}`,
      method: "get",
    });
  },
  updateCustomerSolution(solutionId: number) {
    return request<any, any>({
      url: `${BASE_URL}/updateSolution/${solutionId}`,
      method: "get",
    });
  },
  setRegionSwitchUq(status: number) {
    return request<any, any>({
      url: `${BASE_URL}/setRegionSwitchUq/${status}`,
      method: "get",
    });
  },

  getProductIdByCustomerId(customerId: number) {
    return request<any, Form>({
      url: `${BASE_URL}/getProductId/${customerId}`,
      method: "get",
    });
  },

  addCustomerByAdmin(data: Form) {
    return request({
      url: `${BASE_URL}/createCustomerByAdmin`,
      method: "post",
      data: data,
    });
  },
  updateCustomerByAdmin(data: Form) {
    return request({
      url: `${BASE_URL}/updateCustomerByAdmin`,
      method: "post",
      data: data,
    });
  },
};

export default CustomerAPI;
export interface PageVO {
  customerId: number;
  customerName: string;
  customerStatus: string;
  customerEmail: string;
  customerType: number;
  customerStartAt: Date;
  customerEndAt: Date;
  leftDays: number;
  data: any[];
}

export interface Query extends PageQuery {
  keywords?: string;
  customerType?: number;
}

export interface Form {
  customerId: number;
  customerName: string;
  customerEmail: string;
  customerPassword: string;
  customerType: number;
  customerStatus?: number;
  customerRemark?: string;
  customerStartAt?: Date;
  customerEndAt?: Date;
  solutionId?: number;
  productId?: number;
}

export interface ActiveForm {
  customerEmail: string;
  activeCode?: string;
}

export interface Customer {
  customerName: string;
  solutionId: number;
  customerStartAt: number;
  customerEndAt: number;
  logo: string;
  mainRegionuq: number;
}
